.class Lcom/hyphenate/chat/EMSessionManager;
.super Ljava/lang/Object;


# static fields
.field private static final PREF_KEY_LOGIN_PWD:Ljava/lang/String; = "easemob.chat.loginpwd"

.field private static final PREF_KEY_LOGIN_USER:Ljava/lang/String; = "easemob.chat.loginuser"

.field private static final TAG:Ljava/lang/String; = "Session"

.field private static instance:Lcom/hyphenate/chat/EMSessionManager;


# instance fields
.field private appContext:Landroid/content/Context;

.field public currentUser:Lcom/hyphenate/chat/EMContact;

.field private lastLoginPwd:Ljava/lang/String;

.field private lastLoginUser:Ljava/lang/String;


# direct methods
.method static constructor <clinit>()V
    .locals 1

    new-instance v0, Lcom/hyphenate/chat/EMSessionManager;

    invoke-direct {v0}, Lcom/hyphenate/chat/EMSessionManager;-><init>()V

    sput-object v0, Lcom/hyphenate/chat/EMSessionManager;->instance:Lcom/hyphenate/chat/EMSessionManager;

    return-void
.end method

.method constructor <init>()V
    .locals 1

    const/4 v0, 0x0

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    iput-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->appContext:Landroid/content/Context;

    iput-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->currentUser:Lcom/hyphenate/chat/EMContact;

    iput-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginUser:Ljava/lang/String;

    iput-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginPwd:Ljava/lang/String;

    return-void
.end method

.method public static declared-synchronized getInstance()Lcom/hyphenate/chat/EMSessionManager;
    .locals 3

    const-class v1, Lcom/hyphenate/chat/EMSessionManager;

    monitor-enter v1

    :try_start_0
    sget-object v0, Lcom/hyphenate/chat/EMSessionManager;->instance:Lcom/hyphenate/chat/EMSessionManager;

    iget-object v0, v0, Lcom/hyphenate/chat/EMSessionManager;->appContext:Landroid/content/Context;

    if-nez v0, :cond_0

    sget-object v0, Lcom/hyphenate/chat/EMSessionManager;->instance:Lcom/hyphenate/chat/EMSessionManager;

    invoke-static {}, Lcom/hyphenate/chat/EMClient;->getInstance()Lcom/hyphenate/chat/EMClient;

    move-result-object v2

    invoke-virtual {v2}, Lcom/hyphenate/chat/EMClient;->getContext()Landroid/content/Context;

    move-result-object v2

    iput-object v2, v0, Lcom/hyphenate/chat/EMSessionManager;->appContext:Landroid/content/Context;

    :cond_0
    sget-object v0, Lcom/hyphenate/chat/EMSessionManager;->instance:Lcom/hyphenate/chat/EMSessionManager;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    monitor-exit v1

    return-object v0

    :catchall_0
    move-exception v0

    monitor-exit v1

    throw v0
.end method


# virtual methods
.method clearLastLoginPwd()V
    .locals 3

    :try_start_0
    const-string/jumbo v0, ""

    iput-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginPwd:Ljava/lang/String;

    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->appContext:Landroid/content/Context;

    invoke-static {v0}, Landroid/preference/PreferenceManager;->getDefaultSharedPreferences(Landroid/content/Context;)Landroid/content/SharedPreferences;

    move-result-object v0

    invoke-interface {v0}, Landroid/content/SharedPreferences;->edit()Landroid/content/SharedPreferences$Editor;

    move-result-object v0

    const-string/jumbo v1, "easemob.chat.loginpwd"

    iget-object v2, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginPwd:Ljava/lang/String;

    invoke-interface {v0, v1, v2}, Landroid/content/SharedPreferences$Editor;->putString(Ljava/lang/String;Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;

    invoke-interface {v0}, Landroid/content/SharedPreferences$Editor;->apply()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    :goto_0
    return-void

    :catch_0
    move-exception v0

    goto :goto_0
.end method

.method clearLastLoginUser()V
    .locals 3

    :try_start_0
    const-string/jumbo v0, ""

    iput-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginUser:Ljava/lang/String;

    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->appContext:Landroid/content/Context;

    invoke-static {v0}, Landroid/preference/PreferenceManager;->getDefaultSharedPreferences(Landroid/content/Context;)Landroid/content/SharedPreferences;

    move-result-object v0

    invoke-interface {v0}, Landroid/content/SharedPreferences;->edit()Landroid/content/SharedPreferences$Editor;

    move-result-object v0

    const-string/jumbo v1, "easemob.chat.loginuser"

    iget-object v2, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginUser:Ljava/lang/String;

    invoke-interface {v0, v1, v2}, Landroid/content/SharedPreferences$Editor;->putString(Ljava/lang/String;Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;

    invoke-interface {v0}, Landroid/content/SharedPreferences$Editor;->apply()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    :goto_0
    return-void

    :catch_0
    move-exception v0

    goto :goto_0
.end method

.method getLastLoginPwd()Ljava/lang/String;
    .locals 3

    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginPwd:Ljava/lang/String;

    if-nez v0, :cond_1

    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->appContext:Landroid/content/Context;

    invoke-static {v0}, Landroid/preference/PreferenceManager;->getDefaultSharedPreferences(Landroid/content/Context;)Landroid/content/SharedPreferences;

    move-result-object v0

    const-string/jumbo v1, "easemob.chat.loginpwd"

    const-string/jumbo v2, ""

    invoke-interface {v0, v1, v2}, Landroid/content/SharedPreferences;->getString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    const-string/jumbo v1, ""

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_0

    const-string/jumbo v0, ""

    iput-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginPwd:Ljava/lang/String;

    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginPwd:Ljava/lang/String;

    :goto_0
    return-object v0

    :cond_0
    :try_start_0
    invoke-static {}, Lcom/hyphenate/chat/EMClient;->getInstance()Lcom/hyphenate/chat/EMClient;

    move-result-object v1

    invoke-virtual {v1}, Lcom/hyphenate/chat/EMClient;->getCryptoUtils()Lcom/hyphenate/util/CryptoUtils;

    move-result-object v1

    invoke-virtual {v1, v0}, Lcom/hyphenate/util/CryptoUtils;->decryptBase64String(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    iput-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginPwd:Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    :cond_1
    :goto_1
    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginPwd:Ljava/lang/String;

    goto :goto_0

    :catch_0
    move-exception v0

    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_1
.end method

.method getLastLoginUser()Ljava/lang/String;
    .locals 3

    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginUser:Ljava/lang/String;

    if-nez v0, :cond_0

    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->appContext:Landroid/content/Context;

    invoke-static {v0}, Landroid/preference/PreferenceManager;->getDefaultSharedPreferences(Landroid/content/Context;)Landroid/content/SharedPreferences;

    move-result-object v0

    const-string/jumbo v1, "easemob.chat.loginuser"

    const-string/jumbo v2, ""

    invoke-interface {v0, v1, v2}, Landroid/content/SharedPreferences;->getString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    iput-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginUser:Ljava/lang/String;

    new-instance v0, Lcom/hyphenate/chat/EMContact;

    iget-object v1, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginUser:Ljava/lang/String;

    invoke-direct {v0, v1}, Lcom/hyphenate/chat/EMContact;-><init>(Ljava/lang/String;)V

    iput-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->currentUser:Lcom/hyphenate/chat/EMContact;

    :cond_0
    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginUser:Ljava/lang/String;

    return-object v0
.end method

.method public getLoginUserName()Ljava/lang/String;
    .locals 1

    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->currentUser:Lcom/hyphenate/chat/EMContact;

    iget-object v0, v0, Lcom/hyphenate/chat/EMContact;->username:Ljava/lang/String;

    return-object v0
.end method

.method public setLastLoginPwd(Ljava/lang/String;)V
    .locals 3

    if-nez p1, :cond_0

    :goto_0
    return-void

    :cond_0
    iput-object p1, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginPwd:Ljava/lang/String;

    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->appContext:Landroid/content/Context;

    invoke-static {v0}, Landroid/preference/PreferenceManager;->getDefaultSharedPreferences(Landroid/content/Context;)Landroid/content/SharedPreferences;

    move-result-object v0

    invoke-interface {v0}, Landroid/content/SharedPreferences;->edit()Landroid/content/SharedPreferences$Editor;

    move-result-object v0

    :try_start_0
    invoke-static {}, Lcom/hyphenate/chat/EMClient;->getInstance()Lcom/hyphenate/chat/EMClient;

    move-result-object v1

    invoke-virtual {v1}, Lcom/hyphenate/chat/EMClient;->getCryptoUtils()Lcom/hyphenate/util/CryptoUtils;

    move-result-object v1

    invoke-virtual {v1, p1}, Lcom/hyphenate/util/CryptoUtils;->encryptBase64String(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    const-string/jumbo v2, "easemob.chat.loginpwd"

    invoke-interface {v0, v2, v1}, Landroid/content/SharedPreferences$Editor;->putString(Ljava/lang/String;Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;

    invoke-interface {v0}, Landroid/content/SharedPreferences$Editor;->apply()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    :catch_0
    move-exception v0

    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_0
.end method

.method setLastLoginUser(Ljava/lang/String;)V
    .locals 2

    if-nez p1, :cond_0

    :goto_0
    return-void

    :cond_0
    new-instance v0, Lcom/hyphenate/chat/EMContact;

    invoke-direct {v0, p1}, Lcom/hyphenate/chat/EMContact;-><init>(Ljava/lang/String;)V

    iput-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->currentUser:Lcom/hyphenate/chat/EMContact;

    iput-object p1, p0, Lcom/hyphenate/chat/EMSessionManager;->lastLoginUser:Ljava/lang/String;

    iget-object v0, p0, Lcom/hyphenate/chat/EMSessionManager;->appContext:Landroid/content/Context;

    invoke-static {v0}, Landroid/preference/PreferenceManager;->getDefaultSharedPreferences(Landroid/content/Context;)Landroid/content/SharedPreferences;

    move-result-object v0

    invoke-interface {v0}, Landroid/content/SharedPreferences;->edit()Landroid/content/SharedPreferences$Editor;

    move-result-object v0

    const-string/jumbo v1, "easemob.chat.loginuser"

    invoke-interface {v0, v1, p1}, Landroid/content/SharedPreferences$Editor;->putString(Ljava/lang/String;Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;

    invoke-interface {v0}, Landroid/content/SharedPreferences$Editor;->apply()V

    goto :goto_0
.end method
